﻿using System;
using System.ComponentModel.DataAnnotations;
using Legazpi.Payroll.DataAccess.Repositories;
using Legazpi.Payroll.DataAccess.DataObjects.Enums;
using System.Collections.Generic;


namespace Legazpi.Payroll.DataAccess.DataObjects
{
    public class Employee : EntityBase<int>
    {
                 
        #region Personal Details
        [Required]
        [StringLength(20)]
        public string EmployeeCode { get; set; }
        
        [Required]
        [StringLength(50)]
        public string FirstName { get; set; }

        [Required]
        [StringLength(50)]
        public string MiddleName { get; set; }

        [Required]
        [StringLength(50)]
        public string LastName { get; set; }

        [StringLength(50)]
        public string ContactNo { get; set; }

        [StringLength(200)]
        public string Address { get; set; }

        [StringLength(200)]
        public string Remarks { get; set; }

        private string _gender;
        [StringLength(10)]
        public string Gender 
        {
            get { return _gender != null ? _gender.ToUpper() : string.Empty; }
            set { _gender = value; } 
        }


        [StringLength(50)]
        public string NickName { get; set; }

        public DateTime? DateOfBirth { get; set; }

        [StringLength(50)]
        public string PlaceOfBirth { get; set; }
        [StringLength(50)]
        public string Height { get; set; }
        [StringLength(50)]
        public string Weight { get; set; }
        
        [StringLength(50)]
        public string Qualifier { get; set; }

        [StringLength(50)]
        public string Religion { get; set; }

        [StringLength(50)]
        public string SSSId { get; set; }
        [StringLength(50)]
        public string TinId { get; set; }
        [StringLength(50)]
        public string PhilHealthId { get; set; }
        [StringLength(50)]
        public string PagIbigId { get; set; }

        private string _civilStatus;
        [StringLength(50)]
        public string CivilStatus 
        { 
            get { return _civilStatus != null ? _civilStatus.ToUpper() : string.Empty; }
            set { _civilStatus = value; } 
        }

        [StringLength(50)]
        public string YearsMarried { get; set; }

        [StringLength(50)]
        public string ATMno { get; set; }

        #endregion

        #region Education
        [StringLength(100)]
        public string PrimarySchoolName { get; set; }
        [StringLength(100)]
        public string PrimarySchoolPeriod { get; set; }
        [StringLength(100)]
        public string SecondarySchoolName { get; set; }
        [StringLength(100)]
        public string SecondarySchoolPeriod { get; set; }
        [StringLength(100)]
        public string TertiarySchoolName { get; set; }
        [StringLength(100)]
        public string TertiarySchoolPeriod { get; set; }
        [StringLength(100)]
        public string CollegeDegree { get; set; }
        #endregion

        [Required]
        public int EmployedStatus { get; private set; }
        [NotMapped]
        public EmployedStatus EmployedStatusEnum
        {
            get { return (EmployedStatus)EmployedStatus; }
            set { this.EmployedStatus = (int)value; }
        }
        public DateTime? DateAdded { get; set; }
        public DateTime? DateModified { get; set; }

        [NotMapped]
        public string EmployeeFullname
        {
            get { return string.Format("{0}, {1} {2}", LastName, FirstName, MiddleName); }            
        }
        
        #region References        
        public int? PositionId { get; set; }       
        public int? DetachmentId { get; set; }
        public int? SupervisorId { get; set; }
                  
        public virtual Position Position { get; set; }
        public virtual Detachment Detachment { get; set; }        
        public virtual Employee Supervisor { get; set; }        
        //many to many relation to Payroll
        public virtual ICollection<PayrollSummary> PayrollSummaries { get; set; }
        #endregion

        #region   Constructor        
        public Employee()
        {
            PayrollSummaries = new HashSet<PayrollSummary>();
        }
        #endregion
        #region Methods
        public void SetStatus(int status)
        {
            if (!Enum.IsDefined(EmployedStatusEnum.GetType(), status))
                EmployedStatusEnum = Enums.EmployedStatus.InActive;
            
            EmployedStatusEnum = (EmployedStatus)status;
        }
        #endregion

    }
}
